//
//  BCSvipMenberRewardCell.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/12/21.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "BCSvipMenberRewardCell.h"

@interface BCSvipMenberRewardCell ()

@property (nonatomic, strong) QMUILabel *uidLabel;

/**
 *timeLabel
 */
@property (nonatomic, strong) QMUILabel *timeLabel;

/**
 *rewardLabel
 */
@property (nonatomic, strong) QMUILabel *rewardLabel;

/**
 *rewardCaptionLabel
 */
@property (nonatomic, strong) QMUILabel *rewardCaptionLabel;

@end

@implementation BCSvipMenberRewardCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews {
    CGFloat leftPadding = 15.0*WidthScale;
    //
    self.uidLabel = [QMUILabel new];
    self.uidLabel.textColor = [UIColor qmui_colorWithHexString:@"#505050"];
    self.uidLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular];
    [self.contentView addSubview:self.uidLabel];
    [self.uidLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).offset(leftPadding);
        make.bottom.mas_equalTo(self.contentView.mas_centerY).offset(2.0);
    }];
    //
    self.timeLabel = [QMUILabel new];
    self.timeLabel.textColor = [UIColor qmui_colorWithHexString:@"#AEAEAE"];
    self.timeLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.uidLabel.mas_bottom).offset(3.0);
        make.left.mas_equalTo(self.uidLabel);
    }];
    //
    self.rewardLabel = [QMUILabel new];
    self.rewardLabel.textColor = [UIColor darkMainColor];
    self.rewardLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular];
    [self.contentView addSubview:self.rewardLabel];
    [self.rewardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView).offset(-leftPadding);
        make.bottom.mas_equalTo(self.uidLabel);
    }];
    //
    self.rewardCaptionLabel = [QMUILabel new];
    self.rewardCaptionLabel.textColor = [UIColor qmui_colorWithHexString:@"#AEAEAE"];
    self.rewardCaptionLabel.font = self.timeLabel.font;
    [self.contentView addSubview:self.rewardCaptionLabel];
    [self.rewardCaptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.rewardLabel);
        make.centerY.mas_equalTo(self.timeLabel);
    }];
    
    
    [self addSubview:self.separatorLine];
    [self.separatorLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(leftPadding);
        make.right.mas_equalTo(self).offset(-leftPadding);
        make.bottom.mas_equalTo(self);
        make.height.mas_equalTo(1.0);
    }];
}



- (void)setContent:(BCUserSvipDataSharesContent *)content {
    _content = content;
    self.uidLabel.text = [NSString stringWithFormat:@"UID:%@",content.uid];
    self.timeLabel.text = content.date;
    
    [self setRewardLabelText:content];
    //
    self.rewardCaptionLabel.text = self.svipData.flow.reward;
}
- (void)setRewardLabelText:(BCUserSvipDataSharesContent *)content {
    NSString *rewardText = content.money;
    NSString *curr = self.svipData.buy.cur_sign?:@"";
    //
    NSString *rewardString = [NSString stringWithFormat:@"%@%@",rewardText,curr];
    NSMutableAttributedString *rewardAttributedText = [[NSMutableAttributedString alloc] initWithString:rewardString];
    //
    NSRange currRange = [rewardString rangeOfString:curr];
    if (currRange.location!=NSNotFound) {
        [rewardAttributedText addAttributes:@{NSFontAttributeName:self.rewardCaptionLabel.font} range:currRange];
    }
    self.rewardLabel.attributedText = rewardAttributedText;
}



+ (CGFloat)defaultHeight {
    return 60.0;
}

@end
